package com.atchangsha.system.controller;

import java.util.Arrays;
import java.util.Map;

import com.atchangsha.system.dto.WorkerDTO;
import com.atchangsha.system.dto.WorkerLoginDto;
import org.springframework.web.bind.annotation.*;
import com.atchangsha.system.entity.WorkerEntity;
import com.atchangsha.system.service.WorkerService;
import com.atchangsha.system.common.utils.PageUtils;
import com.atchangsha.system.common.utils.Result;
import javax.annotation.Resource;

/**
 * 员工表
 * @author 卓越班项目第二组
 * @date 2022-04-22 00:49:59
 */
@RestController
@RequestMapping("system/worker")
@CrossOrigin
public class WorkerController {
    @Resource
    private WorkerService workerService;

    /**
     * 分页模糊查询列表
     */
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = workerService.queryPage(params);

        return Result.ok().setResult(page);
    }


    /**
     * 根据id查看详情
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		WorkerEntity worker = workerService.getById(id);

        return Result.ok().setResult(worker);
    }

    /**
     * 员工注册
     * @param workerLoginDto
     * @return
     */
    @PostMapping("/registry")
    public Result registry(@RequestBody WorkerLoginDto workerLoginDto){
		return workerService.registry(workerLoginDto);
    }

    /**
     * 修改员工信息
     */
    @PutMapping("/update")
    public Result update(@RequestBody WorkerDTO workerDTO){
		return workerService.updateMessage(workerDTO);
    }

    /**
     * 删除员工信息
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Long[] ids){
		workerService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
